//
//  UIImageView+Extension.swift
//  WB
//
//  Created by 汪鹏 on 2017/1/7.
//  Copyright © 2017年 汪鹏. All rights reserved.
//  隔离SDWebImage框架

import Foundation
import SDWebImage

extension UIImageView {
    
    
    /// 隔离SDWebImage框架
    ///
    /// - Parameters:
    ///   - urlString: 路径
    ///   - placeholderImage: 占位图片
    ///   - isIcon: 是否是头像
    func wp_setImage(urlString:String?, placeholderImage:String?, isIcon:Bool = false) {
        
        guard let urlString = urlString,
            let url = URL(string: urlString)else {
            
            image = UIImage(named: placeholderImage ?? "")
            
            return
        }
        
        let img = UIImage(named: placeholderImage ?? "")
        
        sd_setImage(with: url, placeholderImage: img, options: []) { [weak self] (image, _, _, _) in
            
            if isIcon == true {
                
                self?.image = image?.conerRadius(rect: (self?.bounds)!, backColor: UIColor.white)
            
                }
            }
        }
    }
